package cate.common.table.res.holy_pet.scene_spot;

import cate.common.table.EExcelNoteField;
import cate.common.table.EExcelRowClass;
import cate.common.table.ERow;
import cate.common.util.random.RWItem;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * 灵宠-征途景点 Row
 *
 * @author ShenSL
 * @since 2023/8/24 15:01
 */
@Slf4j
@EExcelRowClass
public class HolyPetSceneSpotRow extends ERow {
    @EExcelNoteField(fieldName = "场景类型")
    public int sceneId;
    @EExcelNoteField(fieldName = "景点枚举")
    public int placeId;
    @EExcelNoteField(fieldName = "开启条件")
    public int condition;
    @EExcelNoteField(fieldName = "游玩奖励")
    public String missionRewardStr;
    @EExcelNoteField(fieldName = "消耗精力")
    public int needEnergy;
    @EExcelNoteField(fieldName = "任务时间")
    public int missionTimeSec;
    @EExcelNoteField(fieldName = "奇遇事件")
    public String adventureStr;
    @EExcelNoteField(fieldName = "奇遇间隔")
    public int adventureDurationSec;
    @EExcelNoteField(fieldName = "奇遇概率")
    public int adventureProb;
    @EExcelNoteField(fieldName = "协助奖励")
    public String supportRewardStr;

    @NoteField("奇遇随机列表")
    public List<AdventureRWItem> items = new ArrayList<>();

    @NoArgsConstructor
    @AllArgsConstructor
    @NoteClass("奇遇随机项")
    public static class AdventureRWItem implements RWItem {
        @NoteField("奇遇ID")
        public int adventureId;
        @NoteField("权重")
        public double weight;

        @Override
        public double getWeight() {
            return weight;
        }
    }

    @Override
    public void decode() {
        super.decode();
        items.clear();
        try {
            String[] splits = adventureStr.split("#");
            for (String sub : splits) {
                String[] sp = sub.split(":");
                items.add(new AdventureRWItem(Integer.parseInt(sp[0]), Double.parseDouble(sp[1])));
            }
        } catch (Exception e) {
            log.error("", e);
        }
    }
}
